$(function () {
	
    var itemIndex = 0;
    var NO = 0;
    var tabLoadEndArray = [false];
    var tabLenghtArray = [0];
    $.ajax({
//		headers:{'Cookie':document.cookie},
		type:"POST", 
	    url:"http://127.0.0.1:9035/pointActivity/api/v1/getCountAdvisor",
// 	    url:rootPath + "/pointActivity/api/v1/insertVoter",
	    dataType:"json",
	    contentType:"application/json",
	    success:function(data){
	    	var i = data.result;
	    	tabLenghtArray = [i];
	    }
	})
    // dropload
    var dropload = $('.khfxWarp').dropload({
        scrollArea: window,
        domDown: {
            domClass: 'dropload-down',
            domRefresh: '<div class="dropload-refresh">上拉加载更多</div>',
            domLoad: '<div class="dropload-load"><span class="loading"></span>加载中...</div>',
            domNoData: '<div class="dropload-noData">已无数据</div>'
        },
        loadDownFn: function (me) {
            setTimeout(function () {
                if (tabLoadEndArray[itemIndex]) {
                    me.resetload();
                    me.lock();
                    me.noData();
                    me.resetload();
                    return;
                }
                var result = '';
                var advisorId = '';
                $.ajax({
//             		headers:{'Cookie':document.cookie},
            		type:"POST", 
            	    url:"http://127.0.0.1:9035/pointActivity/api/v1/getAdvisor?min="+NO,
//             	    url:rootPath + "/pointActivity/api/v1/insertVoter",
            	    dataType:"json",
            	    contentType:"application/json",
            	    success:function(data){
            	    	console.log(data);
            	    	var list = data.resultList;
            	    	if(list.length > 0){
            	    		for(var i = 0; i < 3; i++){
            	    			if (tabLenghtArray[itemIndex] > 0) {
            	    				 tabLenghtArray[itemIndex]--;
            	    				 } 
            	    			 else {
            	    				 tabLoadEndArray[itemIndex] = true; 
            	    				 break;
            	    				 }
            	    			 if(itemIndex == 0){
            	    				 result +="<li>";
            	    				 	result +="<div class='left_box'>";
            	    				 		result +="<img class='block' src='"+list[i].ADVISOR_PHOTO+"' alt=''>";
            	    				 		result +="<div class='cont-wrap'>";
            	    				 			result +="<p>"+list[i].ADVISOR_ID+"."+list[i].ADVISOR_NAME+"</p>";
            	    				 			result +="<span class='inline-block width-50'>"+list[i].TICKETS+"票"+"</span>";
            	    				 			result +="<a class='inline-block a-btn'>投票</a>";
            	    				 		result +="</div>";
            	    				 	result +="</div>";
            	    				 	result +="<div class='right_box'>";
            	    				 		result +="<p>姓名："+list[i].ADVISOR_NAME+"</p>";
            	    				 		result +="<p>店名："+list[i].DEALER_NAME+"</p>";
            	    				 		result +="<p>参赛宣言：</p>";
            	    				 		result +="<p>"+list[i].ADVISOR_DECLARATION+"</p>";
            	    				 	result +="</div>";
            	    				 result +="</li>";
//            	    			$('#khfxPane').append(result);
            	    				 NO = list[i].RN;
            	    				 console.log(NO);
            	    				 $('#www').eq(itemIndex).append(result);
            	    				  
            	    				 advisorId = list[i].ADVISOR_ID;
            	    				 
            	    				 $(".a-btn").click(function(){
            	    					 console.log(advisorId);
            	    						$.ajax({
//            	    				 			headers:{'Cookie':document.cookie},
            	    							type:"POST", 
            	    						    url:"http://127.0.0.1:9035/pointActivity/api/v1/doVote?advisorId="+advisorId,
//            	    				 		    url:rootPath + "/pointActivity/api/v1/doVote",
            	    						    dataType:"json",
            	    						    contentType:"application/json",
            	    						    success:function(data){
            	    						    	var message = data.message;
            	    						    	if(message == "0"){
            	    						    		showAlert("您不是会员或车主，无法参与投票！",hideAlert);
            	    						    	}
            	    						    	else if(message == "1"){
            	    						    		showAlert("您今日票数已投完，明天可以再投！",hideAlert);
            	    						    	}
            	    						    	else{
            	    						    		showAlert("您已成功投出一票！",hideAlert);
            	    						    	}
            	    						    }
            	    						})
            	    					});
            	    				 }
            	    			 }
            	    		}
            	    	}
                });
                me.resetload();
            }, 500);
        }
    });
});